#!/bin/bash
#
# name: create_new_account.sh
# auth: doctype <https://t.me/ndiey>
# desc:
##
clear

if [ "${EUID}" -ne 0 ]; then
    echo "You need to run this script as root" && exit 1
fi

read -p "Enter username: " UserName
read -p "Enter password: " UserPass
read -p "Active duraion [Day]: " ActiveTime

todayDate=$( date +%s )
activeDuration=$(( $ActiveTime * 86400 ))
totalActive=$(( $todayDate + $activeDuration ))
expireDate=$( date -u --date="1970-01-01 $totalActive sec GMT" +%F )
egrep "^$UserName" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
    echo "Nama pengguna sudah diguna!" && exit 0
fi
useradd $UserName
usermod -s /bin/false $UserName
usermod -e $expireDate $UserName
echo -e "$UserPass\n$UserPass" | passwd $UserName &>/dev/null

clear
echo
echo "========================== [ ACCOUNT DETAIL ]"
echo "  Address: $GETIP"
echo " Hostname: $GETHOST"
echo " Username: $UserName"
echo " Password: $UserPass"
echo " Duration: $ActiveTime days"
echo "  Expired: $expireDate"
echo "---------------------------------------------"
echo "Copyright 2021 Cybertize, Allright Reserved."
echo "============================================="
echo
